// ref
// https://blog.csdn.net/weixin_42958308/article/details/103138163

String command = "";  // 接收无线数传数据
void setup() {
  Serial.begin(9600);
  Serial.println("Serial monitor starts successfully!");
}

void loop() {
  while (Serial.available() > 0) {
    command += char(Serial.read());
    delay(2);
  }

  int x_placeinstring = 0;
  int y_placeinstring = 0;
  int z_placeinstring = 0;
  String x_command;
  String y_command;
  String z_command;
  int x_int;
  int y_int;
  int z_int;
  if (command.length() > 0) {
    Serial.println(command);
    x_placeinstring = command.indexOf('x');
    y_placeinstring = command.indexOf('y');
    z_placeinstring = command.indexOf('z');
    x_command = command.substring(x_placeinstring + 1, y_placeinstring);
    y_command = command.substring(y_placeinstring + 1, z_placeinstring);
    z_command = command.substring(z_placeinstring + 1);
    x_int = x_command.toInt();
    y_int = y_command.toInt();
    z_int = z_command.toInt();
    Serial.println(x_int);
    Serial.println(y_int);
    Serial.println(z_int);
    if (x_int == 1)
      for (int i = 1500; i <= 2000; i += 100) {
        ESC.write(i);
        delay(2000);
      }
      for (int i = 2000; i >= 1000; i -= 100) {
        ESC.write(i);
        delay(2000);
      }
      //   delay(2000);
      // ESC.write(500);
      //   delay(2000);
      // ESC.write(1000);
    command = ""; 
  }
}